# -*- coding: utf-8 -*-
import json
# import paramiko
# from scp import SCPClient
import os
import sys

# curPath = os.path.split(sys.argv[0])[0]
# curPath = os.path.split(sys.argv[0])[0]
# uploadConfigPath = os.path.join(curPath, "projectConfig.json")
uploadConfigPath= 'projectConfig.json'
# projectName = sys.argv[1] #项目名称
projectName = 'fengyun' #项目名称
# gameInfoKey = sys.argv[2] #debug or release
gameInfoKey = 'debug' #debug or release
localGameInfoPath = None  # 本地文件路径

def get_upload_config():
    with open(uploadConfigPath) as c:
        cf = json.load(c)
        global localGameInfoPath
        localGameInfoPath = cf[projectName]['LocalGameInfoPath']
        return cf[projectName]["GameInfoConfig"][gameInfoKey]

uploadConfig = get_upload_config()
host = uploadConfig["serverip"]  # 服务器ip地址
port = uploadConfig["port"]  # 端口号
username = uploadConfig["username"]  # ssh 用户名
password = uploadConfig["password"]  # 密码
remotePath = uploadConfig["remotePath"]  # 文件远程路径


# print(host,port,username,password,remotePath, sep='\n')

def upload_file():
    ssh_client = paramiko.SSHClient()
    ssh_client.set_missing_host_key_policy(paramiko.AutoAddPolicy)
    ssh_client.connect(host, port, username, password)
    scpClient = SCPClient(ssh_client.get_transport(), socket_timeout=15.0)
    try:
        scpClient.put(localGameInfoPath, remotePath)
    except FileNotFoundError as e:
        print(e)
        print("系统找不到指定文件" + localGameInfoPath)
    else:
        print("文件上传成功")
    ssh_client.close()


# if __name__ == "__main__":
    # upload_file()



